package com.android.settings.audio.peq.qr.decoder;


import static com.android.settings.audio.peq.qr.Constant.QR_SCHEMA_V1_MSEB;

import android.text.TextUtils;

import com.android.settings.audio.peq.qr.QrManager;
import com.android.settings.audio.peq.qr.annotation.QrImpl;
import com.android.settings.audio.peq.soundeffect.PluginDataManager;
import com.android.settings.audio.peq.util.BuildConfig;
import com.android.settings.audio.peq.util.LogPlus;


/**
 * Created by We on 2023/5/24
 */
@QrImpl(id = QR_SCHEMA_V1_MSEB)
public class MsebV1Decoder extends QrManager.AbsDecoder {
    public MsebV1Decoder() {
        this.id = QR_SCHEMA_V1_MSEB; //by inject
    }

    @Override
    public boolean canDecode(String content) {
        return content.startsWith(this.id);
    }

    @Override
    public Object onDecoded(String content) throws Exception {
        //todo 解析二维码内容&动作
        if (TextUtils.isEmpty(content)) {
            throw new IllegalArgumentException("content is null");
        }
        content = content.substring(this.id.length());

        if (BuildConfig.DEBUG) LogPlus.d("###content:" + content);
        return PluginDataManager.getInstance().<PluginDataManager.MsebData>jsonToData(content, PluginDataManager.MsebData.class);
    }
}
